package com.rules.admin.expression;

public class SpecialExpression implements Expression {
   private String type;
   private String code;
   private String source;
   private String value;

   public SpecialExpression(String type, String code, String source, String value) {
      this.type = type;
      this.code = code;
      this.source = source;
      this.value = value;
   }

   public void accept(ExpressionVisitor visitor) {
      visitor.vistor((Expression)this);
   }

   public String getType() {
      return this.type;
   }

   public void setType(String type) {
      this.type = type;
   }

   public String getCode() {
      return this.code;
   }

   public void setCode(String code) {
      this.code = code;
   }

   public String getSource() {
      return this.source;
   }

   public void setSource(String source) {
      this.source = source;
   }

   public String toString() {
      if ("execute".equals(this.type) && "list".equals(this.code)) {
         return "skip_test = false;\nList list =  " + this.source.replace("$variable", "$context") + ";\nfor(Object obj:list){;\nif(!skip_test){";
      } else if ("execute".equals(this.type) && "listEnd".equals(this.code)) {
         return "};\n}";
      } else if ("execute".equals(this.type) && "judge".equals(this.code)) {
         return "if(" + this.source + "){";
      } else if ("execute".equals(this.type) && "elseJudge".equals(this.code)) {
         return "} else if(" + this.source + "){";
      } else if ("execute".equals(this.type) && "judgeEnd".equals(this.code)) {
         return "}";
      } else if ("execute".equals(this.type) && "else".equals(this.code)) {
         return "}else{";
      } else if ("execute".equals(this.type) && "list2".equals(this.code)) {
         return "skip_test = false;\nfor(Object obj:(List)(" + this.value + ")){;\nif(!skip_test){";
      } else if ("execute".equals(this.type) && "listBreak".equals(this.code)) {
         return "skip_test = true";
      } else {
         return "execute".equals(this.type) && "listContinue".equals(this.code) ? "continue" : this.value;
      }
   }
}
